AddProduct = {
	saveConfig:function (){

			var pid = document.getElementById("pid").value;
			var product = document.getElementById("pro").value;
			//var preVersion = document.getElementById("preVersion").value;
			var postVersion = document.getElementById("postVersion").value;
			var ip = document.getElementById("ip").value;
			var mask = document.getElementById("mask").value;
			var gateway = document.getElementById("gateway").value;
			var dns = document.getElementById("dns").value;
			//var workContent = document.getElementById("workContent").value;
			var workNote = document.getElementById("workNote").value;
			var nodes = document.getElementById("nodes").value;
			var module = document.getElementById("module").value;
			var outDate = document.getElementById("outDate").value;
			var licenseTime = document.getElementById("licenseTime").value;
			
			var hardwareSource = document.getElementById("hardwareSource").value;
			var productConfig = document.getElementById("productConfig").value;
			
			var defaultModule = "";
			var customModule = "";
			
			if("定制模块"==module){
				customModule = document.getElementById("customModuleProduct").value;
			}else{
				defaultModule = document.getElementById("defaultModuleProduct").value;
			}
			
			if(product==0||product==''){
				   PigossMsg.alert("产品名称不能为空！");
				   return;
			}
			
			if(ip==0||ip==''){
				   PigossMsg.alert("IP不能为空！");
				   return;
			}else{
				var rightForm = false;
				var pattern1 = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g;
				if(pattern1.test(ip)){
					rightForm = true;
					var value = ip.split('.');
					for (var i=0; i<value.length; i++){
							if (!(value[i] >= 0 && value[i] <= 255)) {
								PigossMsg.alert("IP不符合规则！");
								return;
							}
					}
				}else{
					rightForm = false;
					PigossMsg.alert("IP不符合规则！");
					return;
				}
			}
			
			if(nodes==0||nodes==''){
				   PigossMsg.alert("节点数不能为空！");
				   return;
			}else{
				var isExit = false;
				var pattern2 = /^[0-9]*[1-9][0-9]*$/;
				if (pattern2.test(nodes)){
					isExit = true;
				}else if(isExit!=true){
					PigossMsg.alert("节点数不符合规则！");
					return;
				}
			}			

			AjaxUtil.request({
				url : 'add_product.action',
				params : {hardwareSource:hardwareSource,productConfig:productConfig,projectId:pid,product:product,postVersion:postVersion,ip:ip,mask:mask,gateway:gateway,dns:dns,workNote:workNote, nodes:nodes,defaultModule:defaultModule,customModule:customModule,outDate:outDate,licenseTime:licenseTime},
				success :function(responseText){
					//PigossMsg.alert("添加成功!");
					RefreshProduct.refresh();
				},
				failure : function(){
					PigossMsg.alert("Added Failure!");
				}
			});
			imgCloseShow();
		
		}
};

RefreshProduct= {
	   refresh:function(){
	       document.getElementById("queryProductByCondition").submit();
	   }
};

EditProduct = {
		editProduct:function(){
			
			var id = document.getElementById("id").value;
			var product = document.getElementById("pro").value;
			//var preVersion = document.getElementById("preVersion").value;
			var postVersion = document.getElementById("postVersion").value;
			var ip = document.getElementById("ip").value;
			var mask = document.getElementById("mask").value;
			var gateway = document.getElementById("gateway").value;
			var dns = document.getElementById("dns").value;
			//var workContent = document.getElementById("workContent").value;
			var workNote = document.getElementById("workNote").value;
			var nodes = document.getElementById("nodes").value;
			var module = document.getElementById("editModuleProduct").value;
			var outDate = document.getElementById("outDate").value;
			var licenseTime = document.getElementById("licenseTime").value;
			
			var hardwareSource = document.getElementById("hardwareSource").value;
			var productConfig = document.getElementById("productConfig").value;
			
			var defaultModule = "";
			var customModule = "";
			
			if("定制模块"==module){
				customModule = document.getElementById("showEditModuleProduct").value;
			}else{
				defaultModule = document.getElementById("eidtDefaultModuleProduct").value;
			}
			
			AjaxUtil.request({
				url : 'update_product.action',
				params : {hardwareSource:hardwareSource,productConfig:productConfig,id:id,product:product,postVersion:postVersion,ip:ip,mask:mask,gateway:gateway,dns:dns,workNote:workNote,nodes:nodes,defaultModule:defaultModule,customModule:customModule,outDate:outDate,licenseTime:licenseTime},
				success :function(responseText){
					//window.location.reload();
					//PigossMsg.alert("Update Success!");
					RefreshProduct.refresh();
				},
				failure : function(){
					PigossMsg.alert("Update Failure!");
				}
			});
			imgCloseShow();			
		},

		del:function(pid){
			AjaxUtil.request({
				url : 'delete_product.action',
				params : {id:pid},
				success : function(responseText){
					//PigossMsg.alert("Delete Success!");
					//window.location.reload();
					RefreshProduct.refresh();
				},
				failure : function(){
					PigossMsg.alert("Delete Failure!");
				}
			});			
		}
};